﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace psafth.FSR.Lapcounter.UserControls
{
    public partial class DisplayEventControl : UserControl
    {
        public DisplayEventControl()
        {
            InitializeComponent();
        }

        public DisplayEventControl(Event raceEvent)
        {
            InitializeComponent();
            this.lblHeader.Text = string.Format("{0} - {1}", raceEvent.EventName, raceEvent.EventDate.ToString("yyy-MM-dd"));

            int nextYPos = 40;

            Button showButton = new Button();
            showButton.Click += (sender, e) => { showButton_Click(sender, e, raceEvent); };
            showButton.Text = "Visa";
            showButton.Width = 50;
            showButton.Location = new Point(400, nextYPos);
            this.Controls.Add(showButton);

            foreach (Heat heat in raceEvent.Heats)
            {
                Label label = new Label();
                label.Text = heat.DisplayTitle;
                label.Width = 400;
                label.Font = new Font(label.Font.FontFamily.Name, 10);
                label.Location = new Point(0, nextYPos);
                this.Controls.Add(label);

                Button raceButton = new Button();
                raceButton.Click  += (sender, e) => { raceButton_Click(sender, e, heat); };
                raceButton.Text = "Kör";
                raceButton.Width = 50;
                raceButton.Location = new Point(450, nextYPos);
                this.Controls.Add(raceButton);

               

                nextYPos = label.Location.Y + label.Height + 15;
            }
        }

        void raceButton_Click(object sender, EventArgs e, Heat h)
        {
            MainForm m = this.ParentForm as MainForm;

            m.SetPageToRace(h);
        }

        void showButton_Click(object sender, EventArgs e, Event raceEvent)
        {
            //StartReportControl r = new StartReportControl(raceEvent);
        }

        private void dataRepeater1_CurrentItemIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
